<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>定时器的用法</title>
</head>
<body>
    <div id="app">
        <button @click='stop'>停止定时器</button>
        <p v-show='isShow'>HELLO WORLD!</p>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                isShow: true,
            },
            methods: {
                stop() {
                    this.$destroy()
                }
            },
            mounted() {
                this.intervalId = setInterval(() => {
                    console.log('1')
                    this.isShow = !this.isShow
                }, 1000)
            },
            beforeDestroy() {
                clearInterval(this.intervalId)
            },
        })
    </script>
</body>
</html>